gameblenderfandomcom-20200214-history
Creating BGE Libraries
__TOC__ =General= No libraries = no usage. It seems there are not that many library files for BGE available in the net. If you are here I think you want to learn how to create you own. As an example lets create a small library with a set of assets for a game level. As I do not want to go into the eternal deep of mesh modelling we create a library of mesh pimitives. =Linkable Object= *We start with the default scene. With that we already have a cube in the middle of the scene. This position is ideal as the group instances add there objects relative from the scene center (0,0,0) if no offset is specified. *Just save the file under the name "Primitives.blend" and we are done. Yes it is done! You can now link the object "Cube" from another file "Level.blend". "Cube" is our first linkable object. =Linkable Group= If you linked cube we see we can't place cube somewhere else than where it is already. This is not really helpful for level creation. So we assign "Cube" to a group: *First some organization: rename the scene "Scene" to "Groups" so we know this scene contains groups. This is optional but can help us later to identify the right scenes. *Go back to the library file. Select "Cube" and open the Object buttons. Here you add a new group. Call it "Cube" - the same as the Cube's name. *The object "Cube" gets now a green border that marks it as part of a group. The nice thing with groups is you can test it in the same file. *Add a new scene. Name it "Test.Cube". *Now add an instance of the group Cube: Add > Group Instance > Cube You see an empty (pivot) appears with the name of the group. Because "Cube" already exists the empty's name gets a prefix to make it unique. Together with the empty a copy of the cube appears (not green). This is the instance. The cube is not selectable. Everytime you try that the pivot gets selected. *If you move the pivot around the "Cube" follows. Also rotation and scale are copied to the "Cube". So you have the possiblity to apply transformations to the instance. *You can create as much group instances as you like. Which makes them perfect for level editing. The user do not even need to care the logic or animation. *Save the file and you are done ... again! To use your group in another file, open the "Level.blend" link the Group "Cube" (not the object!). After linking the group "Cube" is available to be added as group instance as described earlier. =Linkable Scene= Now lets add another asset to our library: *Open the file "Primitives.blend". Go to scene "Groups". *Add a sphere "Sphere". Create a new group "Sphere" and assign object "Sphere" to this group. Now you could save and link the group "Sphere" into your "Level.blend", but you need to link each single group! If you have a lot of groups, this is hard work and you have to do that for each single file. To make it more userfriendly we place them in a scene and let the user link the scene rather than each single group. My recommendation for a naming convention _.lib *Underline makes it appear at the top of the scene names *filename let you easily identify in which file the scene is located *.lib show it is a scene of a library (and should not be used in the BGE) So we create such scene for our library. *Create an empty scene called "_Primitives.lib". *Add a group instance "Cube" and a goup instance "Sphere" Make sure you place as less as possible objects in the scene (no camera, no llight). Only the group instances are important!. *Save the file. and done! To use your groups in another file, open the "Level.blend" link the Scene "_Primitives.lib". After linking all groups ("Cube"and "Sphere") is available to be added as group instance as described earlier. So you see you can create huge libraries that can easily be used. BTW. This technique was used in yoFrankie. I hope you have fun with it. =Short Summary= To create a library file: *create a scene "Groups" (optional) *add your objects for a group *add groups and assign the objects to the group *add a scene "_.lib" *add a group instance of the groups you created